package kr.hkit.androidcomplete02.ch13;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Toast;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.TextView;

public class DatePickerEx extends Activity {
	DatePicker mDate;
	TextView mTxtDate;
	Button mBtn;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch13_datepickerex);

		mDate = (DatePicker) findViewById(R.id.ch13_datepicker);
		mTxtDate = (TextView) findViewById(R.id.ch13_datepicker_tv);
		mDate.init(mDate.getYear(), mDate.getMonth(), mDate.getDayOfMonth(),
				new OnDateChangedListener() {
					public void onDateChanged(DatePicker view, int year,
							int monthOfYear, int dayOfMonth) {
						mTxtDate.setText(String.format("%d/%d/%d", year,
								monthOfYear + 1, dayOfMonth));
					}
				});

		mBtn = (Button) findViewById(R.id.ch13_datepicker_btn);
		mBtn.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				String result = String.format("%d년 %d월 %d일", mDate.getYear(),
						mDate.getMonth() + 1, mDate.getDayOfMonth());
				Toast.makeText(DatePickerEx.this, result, Toast.LENGTH_SHORT)
						.show();
			}
		});

	}
}
